from sqlalchemy import String, Integer, Column, ForeignKey, Float, Boolean, Text, DateTime
from sqlalchemy.orm import declarative_base, relationship
from sqlalchemy import PrimaryKeyConstraint


Base = declarative_base()


class Product(Base):
    __tablename__ = 'product'

    id = Column(Integer, primary_key=True)
    date = Column(DateTime)
    name = Column(String(250))
    raiting = Column(Float)
    number_of_raitings = Column(Integer)
    link = Column(String(250))
    reviews = relationship(
        'Review',
        backref='product',
        lazy='dynamic'
    )
    points_of_sale = relationship(
        'PointsOfSale',
        backref='product',
        lazy='dynamic'
    )


class Review(Base):
    __tablename__ = 'review'

    id = Column(Integer, primary_key=True)
    evaluation = Column(Integer)
    name = Column(String(50))
    card_number = Column(String(7))
    is_below_four = Column(Boolean)
    description = Column(Text)
    product_id = Column(Integer, ForeignKey('product.id'))


class PointsOfSale(Base):
    __tablename__ = 'points_of_sale'

    id = Column(Integer, primary_key=True)
    address = Column(Text)
    product_id = Column(Integer, ForeignKey('product.id'))
